Skip to content

Synchronize all get value loaders only if value is absent for given key #2082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

miensol
Copy link
Contributor

@miensol miensol commented Jun 11, 2021

See #2079

After this PR, calls to get(key, valueLoader) will be synchronized only in case an initial lookup for value fails.

The synchronization ignores cache key. That is, if 2 threads call the method e.g. get(1, ()-> loadValueFor(1)) and get(2, () -> loadValueFor(2)), at the same time, the loadValueFor calls are going to be executed sequentially.

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

The previous version synchronize all calls to `get(key, valueLoader)`. After this PR the calls to value loader will only be synchronised if we do not have value for the given key.

Improves spring-projects#2079
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 11, 2021
@miensol miensol changed the title Synchronize get with value loader only if value is absent for given key Synchronize all get value loaders only if value is absent for given key Jun 11, 2021
@mp911de mp911de added the type: enhancement A general enhancement label Jun 15, 2021
@mp911de mp911de self-assigned this Jun 15, 2021
@mp911de mp911de added this to the 2.5.2 (2021.0.2) milestone Jun 15, 2021
mp911de pushed a commit that referenced this pull request Jun 15, 2021
RedisCache.get(…) now optimistically fetches the cache value before entering cache-wide synchronization. The previous version synchronized all calls to `get(key, valueLoader)`.

Closes #2079
Original pull request: #2082.
mp911de added a commit that referenced this pull request Jun 15, 2021
Inline valueFromLoader method. Refine tests to not rely on the number of runtime CPU cores.

See #2079
Original pull request: #2082.
mp911de pushed a commit that referenced this pull request Jun 15, 2021
RedisCache.get(…) now optimistically fetches the cache value before entering cache-wide synchronization. The previous version synchronized all calls to `get(key, valueLoader)`.

Closes #2079
Original pull request: #2082.
mp911de added a commit that referenced this pull request Jun 15, 2021
Inline valueFromLoader method. Refine tests to not rely on the number of runtime CPU cores.

See #2079
Original pull request: #2082.
@mp911de
Copy link
Member

mp911de commented Jun 15, 2021

Thank you for your contribution. That's merged, polished, and backported now.

@mp911de mp911de closed this Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants